package com.hliushi.movie.config;

import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页插件配置
 *
 * @author llhuang10
 * @date 2021/10/13 17:20
 */
@MapperScan(basePackages = "com.hliushi.movie.mapper")
@Configuration
public class MybatisPlusConfig {


    /**
     * 配置分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }


    /**
     * sql 分析插件, 可阻断全表更新, 删除的操作
     * 注意点: 该插件仅适用于开发环境, 不使用与生成环境
     * 原因: 有性能损失
     */
    @Bean
    public SqlExplainInterceptor sqlExplainInterceptor() {
        SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();

        List<ISqlParser> list = new ArrayList<>();
        // 全表sql 阻断器
        list.add(new BlockAttackSqlParser());
        sqlExplainInterceptor.setSqlParserList(list);
        return sqlExplainInterceptor;
    }


}
